﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPFStudy.Command;

namespace WPFStudy.ViewModel
{
    /// <summary>
    /// CommandWindow-VM
    /// </summary>
    public class NotifyPropertyChangedWindowVM
        : MyViewModelBase //ViewModelBase实现INotifyPropertyChanged接口，并实现接口的封装
        //,INotifyPropertyChanged //可以通过实现INotifyPropertyChanged
    {
        //public event PropertyChangedEventHandler? PropertyChanged; //已在ViewModelBase中实现 

        private string? name;

        public string? Name
        {
            get { return name; }
            set
            { 
                name = value;
                OnPropertyChanged(nameof(Name));
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name))); //不继承ViewModelBase使用INotifyPropertyChanged接口实现时使用
            }
        }

        private string? title;

        public string? Title
        {
            get { return title; }
            set
            { 
                title = value;
                OnPropertyChanged();
            }
        }



        private int? _count = 0;


        public NotifyPropertyChangedWindowVM()
        {
            NotifyPropertyChangedCmd = new NotifyPropertyChangedWindowCmd(NotifyPropertyChanged);
        }

        public NotifyPropertyChangedWindowCmd NotifyPropertyChangedCmd { get; set; }


        public void NotifyPropertyChanged()
        {
            _count++;
            Name = $"点击了按钮+{_count},{nameof(Name)}";
            Title = $"点击了按钮+{_count},{nameof(Title)}";
            MessageBox.Show(Name,"提示",MessageBoxButton.OK,MessageBoxImage.Information);
        }
    }
}
